import api from '@/src/api';
import { message } from 'antd';

export default {
  namespace: 'equityIndustryRiskM',
  state: {
    dictionary: {},
    searchData: {},
  },
  effects: {
    *findProductTime({ payload, callback }, { call, put }) {
      const response = yield call(api.profitAndLoss.findProductTime, payload);
      if (response && response.data && response.code == 0) {
        callback(response);
      } else {
        message.error((response && response.msg) || '获取时间范围失败');
      }
    },

    //行业敞口明细
    *getIndustryExposureDetail({ payload, callback }, { call, put }) {
      const response = yield call(api.equityIndustryRisk.getIndustryExposureDetail, payload);
      if (response && response.data && response.code == 0) {
        callback(response);
      } else {
        message.error((response && response.msg) || '获取行业敞口明细信息失败');
      }
    },

    //   产品与基准行业敞口
    *getIndustryExposureContrast({ payload, callback }, { call, put }) {
      const response = yield call(api.equityIndustryRisk.getIndustryExposureContrast, payload);
      if (response && response.data && response.code == 0) {
        callback(response);
      } else {
        message.error((response && response.msg) || '获取产品与基准行业敞口信息失败');
      }
    },

    //   根据行业分类获取行业接口
    *queryIndustryCategory({ payload, callback }, { call, put }) {
      const response = yield call(api.equityIndustryRisk.queryIndustryCategory, payload);
      if (response && response.data && response.code == 0) {
        callback(response);
      } else {
        message.error((response && response.msg) || '获取行业列表失败');
      }
    },

    //   收益率分析
    *getIndustryReturnExposure({ payload, callback }, { call, put }) {
      const response = yield call(api.equityIndustryRisk.getIndustryReturnExposure, payload);
      if (response && response.data && response.code == 0) {
        callback(response);
      } else {
        message.error((response && response.msg) || '获取收益率分析信息失败');
      }
    },

    //   累计收益率分析
    *getIndustryCumReturnExposure({ payload, callback }, { call, put }) {
      const response = yield call(api.equityIndustryRisk.getIndustryCumReturnExposure, payload);
      if (response && response.data && response.code == 0) {
        callback(response);
      } else {
        message.error((response && response.msg) || '获取累计收益率分析信息失败');
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },
  },
};
